home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 3 / QRZ Ham Radio Callsign Database - Volume 3.iso / world / mac / digital / sftksrcs.hqx / SoftKiss.src.1.8 / dbo / dbo_genfont.c < prev    next >
C/C++ Source or Header  |  1992-06-21  |  3KB  |  159 lines

  1. /*
  2.  * dbo_genfont.c - generate font image array
  3.  * by Aaron Wohl
  4.  * Public domain
  5.  * 6393 Penn Ave #303
  6.  * Pittsburgh PA, 15208
  7.  * home: 412-731-6159
  8.  * work: 412-268-5032
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include "dbo_stdio.h"
  13. #include "dbo_font.h"
  14. #include <string.h>
  15. #include <time.h>
  16.  
  17. static char *fname="dbo_font.c";
  18. static FILE *of;    /*output file, generated c code*/
  19. static char font_table[DBO_LINE_HEIGHT][DBO_CHARSET_SIZE];
  20.  
  21. /*
  22.  * setup a port to draw in font_table
  23.  */
  24. static void init_port(GrafPtr port)
  25. {
  26.   OpenPort(port);
  27.   port->portBits.baseAddr= (Ptr) font_table;
  28.   port->portBits.rowBytes=DBO_CHARSET_SIZE;
  29.   port->portBits.bounds.top=0;
  30.   port->portBits.bounds.left=0;
  31.   port->portBits.bounds.bottom=DBO_LINE_HEIGHT;
  32.   port->portBits.bounds.right=DBO_CHAR_PIXEL_WIDTH*DBO_CHARSET_SIZE;
  33.   port->portRect=port->portBits.bounds;
  34.   RectRgn(port->visRgn,&port->portRect);
  35.   TextFont(monaco);
  36.   TextSize(9);
  37.   TextFace(condense);
  38. }
  39.  
  40. /*
  41.  * fill in the font_table with the bits for each character
  42.  */
  43. static void fill_font_table()
  44. {
  45.   GrafPort port;
  46.   int line_base;
  47.   int i;
  48.   int cwidth;
  49.   init_port(&port);
  50.   memset(font_table,0,sizeof(font_table));
  51.   for(i=0;i<DBO_CHARSET_SIZE;i++) {
  52.     cwidth=CharWidth(i);
  53.     if(cwidth>DBO_CHAR_PIXEL_WIDTH)cwidth=DBO_CHAR_PIXEL_WIDTH;
  54.     cwidth/=2;
  55.       MoveTo(i*DBO_CHAR_PIXEL_WIDTH+cwidth,DBO_LINE_VOFFSET);
  56.     DrawChar(i);
  57.   }
  58.  
  59.   ClosePort(&port);
  60. }
  61.  
  62. /*
  63.  * print out the bits to make a character
  64.  */
  65. static void dump_char(char achar)
  66. {
  67.     int i;
  68.     char *sep="";
  69.     achar&=0x7f;
  70.     if(achar==0x7f)
  71.         fprintf(of," /* delete 0x7f*/ ");
  72.     else if(achar==' ')
  73.         fprintf(of," /* space %02x */ ",' ');
  74.     else if(achar<' ')
  75.         fprintf(of," /* '^%c' %02x */ ",achar+'@',achar);
  76.     else
  77.         fprintf(of," /* '%c' %02x */ ",achar,achar);
  78.     fprintf(of," {");
  79.     for(i=0;i<DBO_LINE_HEIGHT;i++) {
  80.         fprintf(of,"%s0x%02x",sep,font_table[i][achar]);
  81.         sep=",";
  82.         }
  83.     fprintf(of,"}");
  84. }
  85.  
  86. /*
  87.  * dump start of program
  88.  */
  89. static void dump_header()
  90. {
  91.     time_t now=time(0L);
  92.     fprintf(of,
  93. "/*\n"
  94. " * dbo_font.c - automaticly generated .c file\n"
  95. " * by Aaron Wohl\n"
  96. " * Public domain\n"
  97. " * 6393 Penn Ave #303\n"
  98. " * Pittsburgh PA, 15208\n"
  99. " * home: 412-731-6159\n"
  100. " * work: 412-268-5032\n"
  101. " *\n"
  102. " * genfont.c generated at ");
  103.     fprintf(of,"%s",ctime(&now));
  104.     fprintf(of,
  105. " *\n"
  106. " */\n"
  107. "\n"
  108. "#ifdef DBO_ENABLED\n"
  109. "#include \"dbo_stdio.h\"\n"
  110. "#include \"dbo_font.h\"\n"
  111. "#include <string.h>\n"
  112. "\n"
  113. "unsigned char dbo_draw_font[DBO_CHARSET_SIZE][DBO_LINE_HEIGHT]={\n");
  114. }
  115.  
  116. /*
  117.  * put out end of trailer
  118.  */
  119. static void dump_trailer()
  120. {
  121.     fprintf(of,
  122.         "\n"
  123.         "};\n"
  124.         "#endif\n");
  125. }
  126.  
  127. /*
  128.  * dump out the font table
  129.  */
  130. static void dump_font(void)
  131. {
  132.   int i;
  133.   char *sep="";
  134.   dump_header();
  135.   for(i=0;i<DBO_CHARSET_SIZE;i++) {
  136.     fprintf(of,"%s",sep);
  137.       dump_char(i);
  138.       sep=",\n";
  139.   }
  140.   dump_trailer();
  141. }
  142.  
  143. int main()
  144. {
  145.   printf("dbo_genfont font table generator built on %s %s\n",__DATE__,__TIME__);
  146.   fill_font_table();
  147.   printf("writeing font table to %s\n",fname);
  148.   if((of=fopen(fname,"w"))==0) {
  149.       printf("error opening genfont.c\n");
  150.       return 1;
  151.   }
  152.   dump_font();
  153.   if(fclose(of)!=0) {
  154.       printf("error opening genfont.c\n");
  155.       return 1;
  156.   }
  157.   printf("done ok\n");
  158. }
  159.